/**
 * 
 */
package com.yidu.view;

import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.yidu.bean.TbMember;
import com.yidu.bean.TbShopping;
import com.yidu.message.Message;
import com.yidu.service.TbShopService;
import com.yidu.service.TbShoppingService;

/**
 * 
 * @author liutao
 * @data 2018年7月19日
 * @version 1.0
 */
@Controller
@RequestMapping("/shopping")
public class TbShoppingAction {
	//打印控制台
	Logger logger = Logger.getLogger(TbMemberAction.class);

	//消息信息类
	Message msg = new Message();

	//json
	ObjectMapper mapper = new ObjectMapper();

	@Resource
	private TbShoppingService tbShoppingServiceImpl ;
	
	@RequestMapping("/add")
	@ResponseBody
	public Message add(HttpSession session,String menuId) {
		TbMember member = (TbMember) session.getAttribute("user");
		TbShopping shopping = new TbShopping();
		shopping.setMemId(member.getMemId());
		shopping.setMenuId(menuId);
		shopping.setSopId(UUID.randomUUID().toString());
		int add = tbShoppingServiceImpl.save(shopping);
		if(add>0) {
			msg.setMsg("增加成功");
			msg.setNum(1);
			return msg;
		}else {
			msg.setMsg("增加失败");
			msg.setNum(0);
			return msg;
		}
	}
	@RequestMapping("/findAll")
	@ResponseBody
	public List<TbShopping> findAll(String menuId) {
		return tbShoppingServiceImpl.findAll();
	}
	@RequestMapping("/findByMemId")
	@ResponseBody
	public List<TbShopping> findByMemId(HttpSession session,String memId) {
		TbMember member = (TbMember) session.getAttribute("user");
		System.out.println("进入");
		return tbShoppingServiceImpl.findByMemId(member.getMemId());
	}
	
	@RequestMapping("/findSum")
	@ResponseBody
	public Integer findSum(HttpSession session,String memId) {
		TbMember member = (TbMember) session.getAttribute("user");
		System.out.println("进入");
		return tbShoppingServiceImpl.findSum(member.getMemId());
	}
	@RequestMapping("/findNum")
	@ResponseBody
	public Integer findNum(HttpSession session,String memId) {
		TbMember member = (TbMember) session.getAttribute("user");
		System.out.println("进入");
		return tbShoppingServiceImpl.findNum(member.getMemId());
	}
}
